What is Fuse?
Fuse is a super lightweight library which provides a simple way to do fuzzy searching.
Fuse-RS is a port of https://github.com/krisk/fuse-swift written purely in rust.
Usage
Initializing
The first step is to create a fuse object, with the necessary parameters. Fuse::default, returns the following parameters.
= Fuse
default
Example 1
Simple search.
cargo run --example simple-search
let fuse = default;
let text = "Old Man's War";
let search_text = "od mn war";
let result = fuse.search_text_in_string;
assert_eq!;
Example 2
Search over a string iterable.
cargo run --example iterable-search
let fuse = default;
let books = ;
// Improve performance by creating the pattern before hand.
let search_pattern = fuse.create_pattern;
let results = fuse.search_text_in_iterable;
assert_eq!;
Example 3
Search over a list of items implementing the Fuseable trait.
cargo run --example fuseable-search
Furthermore, you can add a chunk size to run this over multiple threads.
Currently, the chunk size is one, so the chunks of size 1 will be run on seperate threads.
fuse.search_text_in_fuse_list_with_chunk_size;
Example 5
You can look into examples/chunk-search.rs for the source code, and can run the same with:
cargo run --example chunk-search
This searches for a text over a list of 100 items with a chunk size of 10.
Options
As given above, Fuse takes the following options
location
: Approximately where in the text is the pattern expected to be found. Defaults to0
distance
: Determines how close the match must be to the fuzzylocation
(specified above). An exact letter match which isdistance
characters away from the fuzzy location would score as a complete mismatch. A distance of0
requires the match be at the exactlocation
specified, adistance
of1000
would require a perfect match to be within800
characters of the fuzzy location to be found using a 0.8 threshold. Defaults to100
threshold
: At what point does the match algorithm give up. A threshold of0.0
requires a perfect match (of both letters and location), a threshold of1.0
would match anything. Defaults to0.6
maxPatternLength
: The maximum valid pattern length. The longer the pattern, the more intensive the search operation will be. If the pattern exceeds themaxPatternLength
, thesearch
operation will returnnil
. Why is this important? Read this. Defaults to32
isCaseSensitive
: Indicates whether comparisons should be case sensitive. Defaults tofalse